package GUILayer;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;

public class TabbedUI extends JFrame {
	private JTabbedPane tabbedPane;

	private SupplierUI supUI;

	private SalesOrderUI mainUI;

	private OrderListUI orderListUI;

	private CustomerUI customersUI;

	private EmptyUI invoicesUI;

	private ProductUI productsUI;

	//singleton
	private static TabbedUI tabUI;

	private TabbedUI() {
		super("Western Cowboy Shop");
		getContentPane().setLayout(null);

		initializeTabs();
		initializeTabContainer();

		pack();
	}

	public static TabbedUI getInstance() {
		if (tabUI == null) {
			tabUI = new TabbedUI();
		}
		return tabUI;
	}

	public void showTab(int tabIndex) {
		if (tabIndex < 3) {
			tabbedPane.setSelectedIndex(tabIndex);
		}
	}


	private void initializeTabs() {
		mainUI = new SalesOrderUI();
		mainUI.setLayout(null);
		
		orderListUI = new OrderListUI();
		orderListUI.setLayout(null);
		
		customersUI = new CustomerUI();
		customersUI.setLayout(null);
		
		invoicesUI = new EmptyUI();
		invoicesUI.setLayout(null);
		
		productsUI = new ProductUI();
		productsUI.setLayout(null);

		supUI = new SupplierUI();
		supUI.setLayout(null);
	}

	private void initializeTabContainer() {
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(10, 10, 1004, 748);

		//index 0 - Customer
		tabbedPane.addTab("Main", mainUI);

		//index 1
		tabbedPane.addTab("Orders", orderListUI);

		//index 2
		tabbedPane.addTab("Customers", customersUI);

		//index 3
		tabbedPane.addTab("Invoices", invoicesUI);

		//index 4
		tabbedPane.addTab("Products", productsUI);

		//index 5
		tabbedPane.addTab("Suppliers", supUI);

		tabbedPane.setVisible(true);
		add(tabbedPane);
	}
}
